home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_14.lha / 6_14 / 6_14c.c < prev    next >
Text File  |  1993-08-08  |  904b  |  40 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / class string from section 6.9
  6. / rewritten to use member definitions
  7. lass string
  8.  
  9.    struct srep
  10.    {
  11. char *s;    // pointer to data
  12. int n;        // reference count
  13.    };
  14.    srep *p;
  15.  
  16. ublic:
  17.    string(char *);    // string x = "abc"
  18.    string();        // string x;
  19.    string(string &);    // string x = string ...
  20.    string& operator=(char *);
  21.    string& operator=(string &);
  22.    ~string();
  23.    char& operator[](int i);
  24.  
  25.    friend ostream& operator<<(ostream&, string&);
  26.    friend istream& operator>>(istream&, string&);
  27.  
  28.    int operator==(char *s)
  29. { return strcmp(p->s, s) == 0; }
  30.  
  31.    int operator==(string &y)
  32. { return strcmp(p->s, y.p->s) == 0; }
  33.  
  34.    int operator!=(char *s)
  35. { return strcmp(p->s, s) != 0; }
  36.  
  37.    int operator!=(string &y)
  38. { return strcmp(p->s, y.p->s) != 0; }
  39. ;
  40.